package com.example.mobifin_busticket.views.dialogs;

import java.util.ArrayList;

import com.example.mobifin_busticket.R;
import com.example.mobifin_busticket.models.TicketDetailsModel;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

public class PassenegerDetailsDialog extends Dialog implements
		android.view.View.OnClickListener {
	ArrayList<TicketDetailsModel> inventoryList;
	LinearLayout llMain;
	Button btn_ok;
	Context mcontext;
	private static final String BLCKCOLOR = "#000000";
	public PassenegerDetailsDialog(Context context,
			ArrayList<TicketDetailsModel> inventoryList2) {
		super(context);
		// TODO Auto-generated constructor stub
		inventoryList2 = new ArrayList<TicketDetailsModel>();
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.passenger_details_dialog);
		llMain = (LinearLayout) findViewById(R.id.llMain);
		btn_ok = (Button) findViewById(R.id.btn_ok);
		btn_ok.setOnClickListener(this);

		this.inventoryList = inventoryList2;
		this.mcontext = context;
		fillLinearLayout(inventoryList2);
	}

	private void fillLinearLayout(ArrayList<TicketDetailsModel> inventoryList) {
		// TODO Auto-generated method stub
		LinearLayout mLayoutSeatPassenger = null, mLayoutSeatPvalue = null, mLayoutSeatContactNo = null, llMainDaynamic = null;
		llMainDaynamic = new LinearLayout(mcontext);
		for (int i = 0; i < inventoryList.size(); i++) {
			mLayoutSeatPassenger = new LinearLayout(mcontext);
			mLayoutSeatPvalue = new LinearLayout(mcontext);
			mLayoutSeatContactNo = new LinearLayout(mcontext);
			mLayoutSeatPassenger.setOrientation(LinearLayout.HORIZONTAL);
			mLayoutSeatPvalue.setOrientation(LinearLayout.HORIZONTAL);
			mLayoutSeatContactNo.setOrientation(LinearLayout.HORIZONTAL);
			LayoutParams llParamsMain = new LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
            llMainDaynamic.setLayoutParams(llParamsMain);
            llMainDaynamic.setOrientation(LinearLayout.VERTICAL);
            mLayoutSeatPassenger.setLayoutParams(llParamsMain);
            mLayoutSeatPvalue.setLayoutParams(llParamsMain);
            mLayoutSeatContactNo.setLayoutParams(llParamsMain);

            View mView = new View(mcontext);
            mView.setBackgroundColor(Color.parseColor("#70000000"));
            LayoutParams llParamsView = new LayoutParams(
                    LayoutParams.MATCH_PARENT, 2);
            mView.setLayoutParams(llParamsView);

            TextView mTvSeat = new TextView(mcontext);
            TextView mTvSeatName = new TextView(mcontext);
            TextView mTvPassenger = new TextView(mcontext);
            TextView mTvPassengerName = new TextView(mcontext);

            LayoutParams llParams = new LayoutParams(0,
                    LayoutParams.MATCH_PARENT);
            llParams.weight = 1f;

            mTvSeat.setTypeface(null, Typeface.BOLD);
            mTvPassenger.setTypeface(null, Typeface.BOLD);

            mTvSeatName.setTextColor(Color.parseColor(BLCKCOLOR));
            mTvPassengerName.setTextColor(Color.parseColor(BLCKCOLOR));
            mTvSeat.setLayoutParams(llParams);
            mTvSeatName.setLayoutParams(llParams);
            mTvPassenger.setLayoutParams(llParams);
            mTvPassengerName.setLayoutParams(llParams);

            mTvSeat.setGravity(Gravity.RIGHT);
            mTvSeatName.setGravity(Gravity.RIGHT);
            mTvPassenger.setGravity(Gravity.LEFT);
            mTvPassengerName.setGravity(Gravity.LEFT);

            mTvSeat.setText(mcontext.getResources().getString(R.string.seatname));
            mTvSeatName.setText(inventoryList.get(i).getTDseatName());
            mTvPassenger.setText(mcontext.getResources().getString(
                    R.string.passengers));
            mTvPassengerName.setText(inventoryList.get(i).getTDseatName()
                    + ", "
                    + inventoryList.get(i).getage()
                    + " "
                    + inventoryList.get(i).getgender());

            if (i == 0) {
                mLayoutSeatPassenger.addView(mTvPassenger);
                mLayoutSeatPassenger.addView(mTvSeat);
            }
            mLayoutSeatPvalue.addView(mTvPassengerName);
            mLayoutSeatPvalue.addView(mTvSeatName);

            llMainDaynamic.addView(mLayoutSeatPassenger);
            llMainDaynamic.addView(mLayoutSeatPvalue);
            llMainDaynamic.addView(mLayoutSeatContactNo);
            if (!(i == inventoryList.size() - 1)) {
                llMainDaynamic.addView(mView);
            }
        }
        llMain.removeAllViews();
        llMain.addView(llMainDaynamic);
		}

	

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btn_ok:
			dismiss();
			break;

		default:
			break;
		}
	}

}
